﻿@inject IModalService Modal
@if (ShowForm)
{
<div class="simple-form">

    <div class="form-group">
        <label for="first-name">First Name</label>
        <input bind="@FirstName" type="text" class="form-control" id="first-name" placeholder="Enter First Name" />
    </div>

    <div class="form-group">
        <label for="last-name">Last Name</label>
        <input bind="@LastName" type="text" class="form-control" id="last-name" placeholder="Enter Last Name" />
    </div>

    <button onclick="@SubmitForm" class="btn btn-primary">Submit</button>
    <button onclick="@Cancel" class="btn btn-secondary">Cancel</button>
</div>
}
else
{
<div class="alert alert-success" role="alert">
    Thanks @FirstName @LastName, form (Id: @FormId) submitted successfully.
</div>
}

@functions {

    [CascadingParameter] ModalParameters Parameters { get; set; }

    bool ShowForm { get; set; } = true;
    string FirstName { get; set; }
    string LastName { get; set; }
    int FormId { get; set; }

    protected override void OnInit()
    {
        FormId = Parameters.Get<int>("FormId");
    }

    void SubmitForm()
    {
        ShowForm = false;
    }

    void Cancel()
    {
        Modal.Close();
    }

}
